package itdep.common.context.spring;

import itdep.common.domain.Entity;
import org.springframework.security.acls.domain.ObjectIdentityRetrievalStrategyImpl;
import org.springframework.security.acls.domain.SidRetrievalStrategyImpl;
import org.springframework.security.acls.model.ObjectIdentity;
import org.springframework.security.acls.model.ObjectIdentityRetrievalStrategy;
import org.springframework.security.acls.model.Sid;
import org.springframework.security.acls.model.SidRetrievalStrategy;
import org.springframework.security.core.Authentication;

import java.util.List;

/**
 * @author $Author: ikhalopik $ (latest modification by $Author: ikhalopik $:)
 * @version $Revision: 4 $   $Date: 2010-06-10 13:13:16 +0000 (Thu, 10 Jun 2010) $
 */
public class EntityRetrievalStrategy implements SidRetrievalStrategy, ObjectIdentityRetrievalStrategy {
	private static final ObjectIdentityRetrievalStrategy OBJECT_IDENTITY_RETRIEVAL_STRATEGY = new ObjectIdentityRetrievalStrategyImpl();
	private static final SidRetrievalStrategy SID_RETRIEVAL_STRATEGY = new SidRetrievalStrategyImpl();

	@SuppressWarnings({"unchecked"})
	public ObjectIdentity getObjectIdentity(Object domainObject) {
		if (domainObject instanceof Entity) {
			return new EntityObjectIdentity((Entity) domainObject);
		}
		return OBJECT_IDENTITY_RETRIEVAL_STRATEGY.getObjectIdentity(domainObject);
	}

	public List<Sid> getSids(Authentication authentication) {
		return SID_RETRIEVAL_STRATEGY.getSids(authentication);
	}
}
